set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/* *******************************************************************
** DATE :
** Writer :
** Memo :
******************************************************************** */
CREATE PROCEDURE [dbo].[TSP_Store_GetInfo]
(
	@IsTransaction	tinyint			= 0
,	@ErrorCode		int				= 0		OUTPUT
,	@ErrorMessage	nvarchar( 1000 )= ''	OUTPUT


,	@n4StoreNo	int	= NULL OUTPUT--IN
,	@strUserID	varchar(50) = NULL OUTPUT--IN
,	@IsActive	char(1)	= NULL	OUTPUT
,	@strStoreName	nvarchar(200)	= NULL	OUTPUT
,	@strCompanyNo	varchar(30)	= NULL	OUTPUT
,	@strPhone	varchar(30)	= NULL	OUTPUT
,	@strPost	varchar(10)	= NULL	OUTPUT
,	@strAddress	nvarchar(400)	= NULL	OUTPUT
,	@strCityName	nvarchar(20)	= NULL	OUTPUT
,	@IsTakeout	char(1)	= NULL	OUTPUT
,	@strTakeout	nvarchar(100)	= NULL	OUTPUT
,	@IsParking	char(1)	= NULL	OUTPUT
,	@strParking	nvarchar(100)	= NULL	OUTPUT
,	@strStoreSize	varchar(50)	= NULL	OUTPUT
,	@strOpenDate	varchar(20)	= NULL	OUTPUT
,	@strOpenTime	varchar(50)	= NULL	OUTPUT
,	@strPointX	varchar(30)	= NULL	OUTPUT
,	@strPointY	varchar(30)	= NULL	OUTPUT
,	@strDescription	nvarchar(4000)	= NULL	OUTPUT
,	@dtCreateDate	datetime	= NULL	OUTPUT
,	@strManagerName	nvarchar(100)	= NULL	OUTPUT
)
as
Set NOCOUNT ON

-- Frk Default Value
DECLARE @FrkDateNow DateTime
DECLARE @FrkRowCount int
DECLARE @FrkTranCount int
DECLARE @FrkErrorCode int
DECLARE @FrkErrorMessage nvarchar( 1000 )
Set @FrkDateNow = GetDate()
set @FrkTranCount = @@TRANCOUNT
-- Frk Check


If ( @IsTransaction = 0 )
Begin
	If ( @FrkTranCount < 1 )
	Begin
		Set @FrkErrorCode = -1
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Else If ( @FrkTranCount > 1 )
	Begin
		Set @FrkErrorCode = -2
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
End
Else
Begin
	If ( @FrkTranCount <> 0 )
	Begin
		Set @FrkErrorCode = -3
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Begin Tran
End

-- Implementation
IF ( @n4StoreNo IS NOT NULL )
BEGIN
	SELECT
		@n4StoreNo = n4StoreNo
	,	@strUserID = strUserID
	,	@IsActive = IsActive
	,	@strStoreName = strStoreName
	,	@strCompanyNo = strCompanyNo
	,	@strPhone = strPhone
	,	@strPost = strPost
	,	@strAddress = strAddress
	,	@strCityName = strCityName
	,	@IsTakeout = IsTakeout
	,	@strTakeout = strTakeout
	,	@IsParking = IsParking
	,	@strParking = strParking
	,	@strStoreSize = strStoreSize
	,	@strOpenDate = strOpenDate
	,	@strOpenTime = strOpenTime
	,	@strPointX = strPointX
	,	@strPointY = strPointY
	,	@strDescription = strDescription
	,	@dtCreateDate = dtCreateDate
	,	@strManagerName = strManagerName
	FROM
		dbo.TB_Store WITH (NOLOCK)
	WHERE
		n4StoreNo = @n4StoreNo
END
ELSE
BEGIN
	SELECT
		@n4StoreNo = n4StoreNo
	,	@strUserID = strUserID
	,	@IsActive = IsActive
	,	@strStoreName = strStoreName
	,	@strCompanyNo = strCompanyNo
	,	@strPhone = strPhone
	,	@strPost = strPost
	,	@strAddress = strAddress
	,	@strCityName = strCityName
	,	@IsTakeout = IsTakeout
	,	@strTakeout = strTakeout
	,	@IsParking = IsParking
	,	@strParking = strParking
	,	@strStoreSize = strStoreSize
	,	@strOpenDate = strOpenDate
	,	@strOpenTime = strOpenTime
	,	@strPointX = strPointX
	,	@strPointY = strPointY
	,	@strDescription = strDescription
	,	@dtCreateDate = dtCreateDate
	,	@strManagerName = strManagerName
	FROM
		dbo.TB_Store WITH (NOLOCK)
	WHERE
		strUserID = @strUserID
END
-- Frk Error Check
SELECT
	@FrkErrorCode = @@ERROR
,	@FrkRowCount = @@RowCount

-- End

COMPLETE:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Commit Tran
		End
	End
	SET @ErrorCode = 0
	SET @ErrorMessage = ''
	return 0
ERROR:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Rollback Tran
		End
	End
	SET @ErrorCode = @FrkErrorCode
	SET @ErrorMessage = @FrkErrorMessage
	return @FrkErrorCode
